#include <iostream>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;

struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};

class Solution {
public:
    vector<vector<int> > Print(TreeNode* pRoot) {
        vector<vector<int> > v;
        vector<int> tn;
        queue<TreeNode*> s;
        if(pRoot==NULL) return v;
        s.push(pRoot);
        s.push(NULL);
        tn.clear();
        while(!s.empty()){
            TreeNode *t=s.front();s.pop();
            if(t){
                tn.push_back(t->val);
                s.push(t->left);
                s.push(t->right);
            }else{
                if(tn.size()>0){
                    v.push_back(tn);
                    tn.clear();
                }
                if(s.front()!=NULL)
                    s.push(NULL);
            }
        }
        return v;
    }
};
TreeNode* h(){
    TreeNode *p=new TreeNode(1);
    p->left=new TreeNode(3);
    p->right=new TreeNode(2);

    TreeNode *q=p->left;
    q->left=new TreeNode(5);
    q->right=new TreeNode(4);
    q=p->right;
    
    q->left=new TreeNode(7);
    q->right=new TreeNode(6);

    return p;
}

int main(){
    TreeNode *p=h();
    Solution s;
    auto a=s.Print(p);
    for(auto i:a){
        for(auto j:i){
            cout << j<< " ";
        }
        cout << endl;
    }


    return 0;
}